const db = require('../config/db')
const addressModel = '../schema/address'

const Mall = db.MallSequelize   //引入数据库
const address = Mall.import(addressModel)  //实例化

// 添加地址
const addAddress = async (data) =>{
  await address.create(
    {
      name: data.name,
      phone: data.phone,
      address: data.address,
      address_detail: data.address_detail,
      address_detail_id: data.address_detail_id
    }
  )
  return true
}
// 根据address_detail_id获取地址
const getAddress = async (id) => {
  const result = await address.findAll(
    {
      where: {
        address_detail_id: id
      }
    }
  )
  return result
}

module.exports = {
  addAddress,
  getAddress
}